package com.smarthome.web.property.controller.system;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarthome.core.dictionary.SmsTypeService;
import com.smarthome.domain.bean.ShSmsType;
import com.smarthome.domain.common.Result;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

@Controller
@RequestMapping(value="/smsType")
public class SmsTypeController {

	@Resource
	private SmsTypeService smsTypeService;
	
	@RequestMapping("/dataGrid")
	@ResponseBody
	public DataGrid dataGrid(ShSmsType querySmsType,PageHelper page){
		return smsTypeService.queryDatagrid(querySmsType, page);
	}
	
	@RequestMapping("/comboboxs")
	@ResponseBody
	public List<Combobox> getComboboxs(HttpServletRequest req){
		List<ShSmsType> types = smsTypeService.querySmsType(new ShSmsType());
		
		List<Combobox> comboboxs = new ArrayList<Combobox>();
		comboboxs.add(new Combobox("","全部小区"));
		if(null == types) return comboboxs;
		for(ShSmsType type  : types){
			comboboxs.add(new Combobox(type.getId() + "",type.getName()));
		}
		return comboboxs;
	}
	
	@RequestMapping("/addPage")
	public String addPage(HttpServletRequest req){
		return "/system/dictionary/smsTypeAdd";
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public Result add(ShSmsType smsType){
		smsTypeService.add(smsType);
		return Result.success("添加成功！");
	}
	
	@RequestMapping("/editPage")
	public String editPage(HttpServletRequest req,Long id){
		ShSmsType smsType=smsTypeService.querySmsTypeById(id);
		req.setAttribute("smsType", smsType);
		return "/system/dictionary/smsTypeEdit";
	}
	
	@RequestMapping("/edit")
	@ResponseBody
	public Result edit(ShSmsType smsType){
		smsTypeService.add(smsType);
		return Result.success("添加成功！");
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public Result delete(Long id){
		smsTypeService.delete(id);
		return Result.success("删除成功！");
	}
}
